[camera_avfoundation] Fix Swift 6 Sendability warning in CaptureDevice protocol#11634
[camera_avfoundation] Fix Swift 6 Sendability warning in CaptureDevice protocol#11634teclas-gif wants to merge 2 commits intoflutter:mainfrom
Conversation
…e protocol The `setExposureTargetBias` completion handler in the `CaptureDevice` protocol was declared as `((CMTime) -> Void)?`, while the underlying `AVCaptureDevice` conformance expects `(@sendable (CMTime) -> Void)?`. This mismatch produces a warning under `SWIFT_STRICT_CONCURRENCY=targeted` and is a hard error in Swift 6 language mode. Adds `@Sendable` to the closure parameter in the protocol declaration to match the AVFoundation signature.
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the CaptureDevice protocol in camera_avfoundation by adding the @Sendable attribute to the setExposureTargetBias completion handler, along with a version bump to 0.10.1+1. Feedback indicates that this change will cause compilation failures in mock implementations that have not been updated to match the new protocol signature.
| var maxExposureTargetBias: Float { get } | ||
| func setExposureTargetBias( | ||
| _ bias: Float, completionHandler handler: ((CMTime) -> Void)?) | ||
| _ bias: Float, completionHandler handler: (@Sendable (CMTime) -> Void)?) |
There was a problem hiding this comment.
This change to the protocol requirement will cause a compilation error in MockCaptureDevice.swift (and any other implementations of this protocol) because the method signature must match the protocol requirement exactly, including the @Sendable attribute. The PR description's claim that mocks are not affected is incorrect; they must be updated to include @Sendable in both the method signature and the setExposureTargetBiasStub property type to maintain protocol conformance.
- Updates MockCaptureDevice to use @sendable on setExposureTargetBias, keeping it in sync with the CaptureDevice protocol requirement. - Adds testSetExposureTargetBias_completionHandlerIsInvoked to exercise the non-nil handler path and serve as a compile-time regression guard: if @sendable is removed from the protocol the mock conformance breaks.
Description
Fixes a Swift 6 Sendability warning produced when building
camera_avfoundationwithSWIFT_STRICT_CONCURRENCY=targetedor higher (the Xcode 16+ default).Root cause
CaptureDevice.swiftdeclares:AVCaptureDevice(the Apple system type that conforms to this protocol) exposes the same method with a@Sendableclosure:The missing
@Sendableannotation on the protocol requirement creates a Sendability mismatch. UnderSWIFT_STRICT_CONCURRENCY=targetedthis is a warning; in Swift 6 language mode it is a hard error.Fix
Three files changed:
CaptureDevice.swift— adds@Sendableto the completion handler in the protocol declaration to match AVFoundation's signature.MockCaptureDevice.swift— updates the mock to match the new protocol signature (both the stub property type and the method).CameraExposureTests.swift— addstestSetExposureTargetBias_completionHandlerIsInvoked, which:MockCaptureDeviceconforms toCaptureDevice, so if@Sendableis removed from the protocol the mock conformance breaks at compile timeTests
testSetExposureTargetBias_completionHandlerIsInvokedinCameraExposureTests.swiftMockCaptureDevicestub and method signatures to use@SendableChecklist